<!--
 * @description: 
 * @Author: lal
 * @Date: 2020-05-23 11:17:20
 * @LastEditors: lal
 * @LastEditTime: 2020-08-14 16:22:16
-->
<template>
  <div class="container">
    <div>
      <h3>渲染进程=》主进程</h3>
      send
      <input type="text" v-model="value" @change="change" />
      {{ dbValue }}
      <br />
      invoke
      <input type="text" v-model="value" @change="newChange" />
    </div>
    <button id="btn" @click="newWin">新建渲染进程</button>
    <button id="btn" @click="exit">退出</button>
    <button id="btn" @click="download">下载更新</button>
    <div>主进程到渲染进程</div>
    <div>渲染进程=》渲染进程</div>
  </div>
</template>

<script>
const { ipcRenderer } = require("electron");

export default {
  name: "zcs-vue",
  props: {},
  data() {
    return {
      value: 0,
      dbValue: 0,
    };
  },
  computed: {},
  created() {},
  methods: {
    change() {
      ipcRenderer.send("dbValue", this.value);
    },

    async newChange() {
      const res = await ipcRenderer.invoke("dbValue", this.value);
      this.dbValue = res;
    },
    async newWin() {
      const res = await ipcRenderer.invoke("newWin");
      console.log(res);
    },
    exit() {
      ipcRenderer.send("exitApp");
    },
    download() {
      ipcRenderer.send("downloadApp");
    },
  },
  mounted() {
    ipcRenderer.on("dbValueDone", (e, value) => {
      console.log(value);
      this.dbValue = value;
    });
  },
};
</script>

<style scoped lang="scss"></style>
